﻿<%@ Page Language="C#" MasterPageFile="~/SimplePMT.Master" AutoEventWireup="true" CodeBehind="Projects.aspx.cs" Inherits="SimplePMT.Projects" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
    <form name="ajaxForm">
    <table width="100%" cellpadding=3>
        <tr>
            <td style="border:1px solid #6893cf;" valign=top bgcolor="#ffffff">
                <div id="TreeView"><%= ProjectTree %></div>
            </td>
        </tr>
        
    </table>
    </p>
    </form>
    <script>

 <%= TaskJSArray %>
    
        var project = true;
        var tmpio;
        var tmpid;
        var sc = document.getElementById('showCompleted');
        
        function showCompletedSelect(io) {
            if (io.checked) {
                io.checked = false;   
            } else {
                io.checked = true;
            }
            showComplete(io);
        }
        
        function showExpandAllSelect(io) {
            if (io.checked) {
                io.checked = false;   
            } else {
                io.checked = true;
            }
            expandAll(io);
        }
        
        function expandAll(io) {
            for (i=0;i<projectArray.length;i++) {
                if (io.checked) {
                    projectArray[i][1].src = 'images/closed.gif';
                } else {
                    projectArray[i][1].src = 'images/open.gif';
                }
                loadTree(projectArray[i][0], projectArray[i][1]);
            }
        }

         
        
        function showComplete(io) {
            sc = io;
            for (i=0;i<completeArray.length;i++) {
                if (document.getElementById(completeArray[i])) {
                    if (io.checked) {
                        document.getElementById(completeArray[i]).style.display = 'inline';
                    } else {
                        document.getElementById(completeArray[i]).style.display = 'none';
                    }
                }
            }
        }
        
        function openContainer(parentId, containerId) {
            tmpid = parentId;
            var title = 'Add New Task Container';
            if (containerId > 0) {
                title = 'Edit Task Container';
            }
            openModal('TaskContainerView.aspx?id='+ containerId +'&pid='+ parentId, 'SimplePMT - '+ title);
        }

        function openTask(id, containerId, title) {
            openModal('TaskView.aspx?id=' + id + '&cid=' + containerId, 'SimplePMT - Task: ' + title);
        }
        function openFile(id, containerId, title) {
            openModal('FileView.aspx?id=' + id + '&cid=' + containerId, 'SimplePMT - File: ' + title);
        }
        
        var containerSelected = 0;
        function showContainerOptions(id) {
            containerSelected = id;
            document.getElementById('options' + id).style.display = 'inline';
        }

        function hideContainerOptions() {
            document.getElementById('options' + containerSelected).style.display = 'none';
        }
        var attachmentSelected = 0;
        function showAttachmentOptions(id) {
            attachmentSelected = id;
            document.getElementById('attachmentOptions' + id).style.display = 'inline';
        }

        function hideAttachmentOptions() {
            document.getElementById('attachmentOptions' + attachmentSelected).style.display = 'none';
        }
        function reloadParentNode(id, io) {
            document.getElementById('container' + id).innerHTML = '';
            io.src = 'images/closed.gif';
            loadTree(id, io);
        }
        function viewAttachmentDetails(id) {
            alert(id);
        }
        function loadTree(id, io) {
            tmpio = io;
            tmpid = id;
            var el = document.getElementById('container'+ id);
            var tl = document.getElementById('taskList'+ id);
            if (io.src.split('/')[io.src.split('/').length - 1] == 'open.gif') {
                io.src = 'images/closed.gif';
                el.style.display = 'none';
                tl.style.display = 'none';
            } else {
                io.src = 'images/open.gif';
//                if (el.innerHTML.length == 0) {
//                    if (document.getElementById('expandall').checked) {
                        SimplePMT.Ajax.Projects.GetProjectTreeNodeAll(id, function (response) {
                            if (response.error != null) {
                                alert(response.error.Message);
                            }
                            el.innerHTML = response.value;
                            showComplete(sc);
//                            document.getElementById('sourceView').value += '\n'+ response.value;
                        });
//                    } else {
//                        SimplePMT.Ajax.Projects.GetProjectTreeNode(id, false, function (response) {
//                            if (response.error != null) {
//                                alert(response.error.Message);
//                            }
//                            el.innerHTML = response.value;
//                        });
//                    }
//                }
                el.style.display = 'inline';
                tl.style.display = 'inline';
            }
        }
    </script>
</asp:Content>